/**
 * Copyright (C) 2008 aileron.cc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cc.aileron.commons.utility;

import java.util.ArrayList;
import java.util.List;

/**
 * プリミティブ型の配列をListに変換
 * @author Aileron
 *
 */
public class PrimitiveArrayWrapperUtils
{
    /**
     * Listへの変換
     * @param object
     * @return
     */
    public static List<Object> convert(Object object)
    {
        final ArrayList<Object> list = new ArrayList<Object>();
        if(object instanceof byte[])
        {
            for(byte value : (byte[]) object) list.add(value);
        }
        else
        if(object instanceof short[])
        {
            for(short value : (short[]) object) list.add(value);
        }
        else
        if(object instanceof int[])
        {
            for(int value : (int[]) object) list.add(value);
        }
        else
        if(object instanceof long[])
        {
            for(long value : (long[]) object) list.add(value);
        }
        else
        if(object instanceof float[])
        {
            for(float value : (float[]) object) list.add(value);
        }
        else
        if(object instanceof double[])
        {
            for(double value : (double[]) object) list.add(value);
        }
        else
        if(object instanceof char[])
        {
            for(char value : (char[]) object) list.add(value);
        }
        else
        if(object instanceof boolean[]) 
        {
            for(boolean value : (boolean[]) object) list.add(value);
        }
        else
        {
            return null;
        }
        return list;
    }
}